package com.triumphxx.testcase.utils;

import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

/**
 * @author:triumphxx
 * @Date: 2025/9/24
 * @Time: 11:20
 * @微信公众号：思考集结处
 * @网站：http://blog.triumphxx.com.cn
 * @GitHub https://github.com/triumphxx
 * @Desc: 日期比较工具
 **/

public class DateUtil {

    public static int compareDate(String sourceDate,String targetDate){
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime sourceDateTime = LocalDateTime.parse(sourceDate, formatter);
        LocalDateTime targetDateTime = LocalDateTime.parse(targetDate, formatter);
        if(sourceDateTime.toLocalTime().equals(LocalTime.MIDNIGHT)){
            sourceDateTime =sourceDateTime.toLocalDate().atTime(23,59,59);
            System.out.println(sourceDateTime);
        }
        if (sourceDateTime.isBefore(targetDateTime)){
            return -1;
        } else if (sourceDateTime.isAfter(targetDateTime)) {
            return 1;
        }else {
            return 0;
        }
    }
}
